package practice_3_4;

import java.util.Arrays;

//给定一个整型数组, 实现冒泡排序(升序排序)
public class BubbleSort {
    public static void main(String[] args) {
        int[] nums1 = new int[]{12,5,88,9,1,6,78,90,25,33,11,66};
        System.out.println("排序前");
        System.out.println(Arrays.toString(nums1));
        bubbleSort(nums1);
        System.out.println("排序后");
        System.out.println(Arrays.toString(nums1));
    }
    //冒泡排序
    public static void bubbleSort(int[] nums){
        for(int i = 0; i < nums.length - 1; i++){
            boolean flag = true;
            for(int j = 0; j < nums.length - i- 1; j++){
                if(nums[j] > nums[j + 1]){
                    flag = false;
                    int tmp = nums[j];
                    nums[j] = nums[j + 1];
                    nums[j + 1] = tmp;
                }
            }
            if(flag){
                break;
            }
        }
    }
}
